package com.edu.exam.enums.course;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 教室状态枚举
 *
 * <p>定义教室的状态信息，用于教室管理。</p>
 *
 * @author System
 * @version 1.0.0
 * @since 2025-11-17
 */
public enum ClassStatus implements BaseEnum {

    /**
     * 创建中
     */
    CREATING("CREATING", "创建中"),

    /**
     * 已创建
     */
    CREATED("CREATED", "已创建"),

    /**
     * 激活
     */
    ACTIVE("ACTIVE", "激活"),

    /**
     * 未激活
     */
    INACTIVE("INACTIVE", "未激活"),

    /**
     * 维护中
     */
    MAINTENANCE("MAINTENANCE", "维护中"),

    /**
     * 维修中
     */
    REPAIRING("REPAIRING", "维修中"),

    /**
     * 已停用
     */
    DISABLED("DISABLED", "已停用"),

    /**
     * 已废弃
     */
    DEPRECATED("DEPRECATED", "已废弃"),

    /**
     * 已删除
     */
    DELETED("DELETED", "已删除"),

    /**
     * 预订中
     */
    RESERVED("RESERVED", "预订中"),

    /**
     * 使用中
     */
    IN_USE("IN_USE", "使用中"),

    /**
     * 空闲
     */
    AVAILABLE("AVAILABLE", "空闲"),

    /**
     * 不可用
     */
    UNAVAILABLE("UNAVAILABLE", "不可用"),

    /**
     * 考试中
     */
    EXAMINATION("EXAMINATION", "考试中"),

    /**
     * 上课中
     */
    TEACHING("TEACHING", "上课中"),

    /**
     * 清洁中
     */
    CLEANING("CLEANING", "清洁中");

    private final String code;
    private final String description;

    ClassStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 判断是否可用
     *
     * @return 是否可用
     */
    public boolean isAvailable() {
        return this == AVAILABLE || this == ACTIVE;
    }

    /**
     * 判断是否正在使用
     *
     * @return 是否正在使用
     */
    public boolean isInUse() {
        return this == IN_USE || this == EXAMINATION || this == TEACHING;
    }

    /**
     * 判断是否不可用
     *
     * @return 是否不可用
     */
    public boolean isUnavailable() {
        return this == UNAVAILABLE || this == MAINTENANCE || 
               this == REPAIRING || this == DISABLED || this == DELETED;
    }

    /**
     * 根据编码获取对应的枚举
     *
     * @param code 编码
     * @return 对应的枚举
     */
    public static ClassStatus fromCode(String code) {
        for (ClassStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown class status code: " + code);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}
